home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / lambda.sty < prev    next >
Encoding:
Text File  |  1990-07-10  |  2.8 KB  |  117 lines

  1. % Filename: Lambda.sty
  2. % Author: Alan Jeffrey
  3. % Last modified: 12 Feb 1990
  4. %
  5. % This style is (c) 1990 Alan Jeffrey.  Permission is granted to make
  6. % copies, as long as
  7. %
  8. % a) no deletions are made,
  9. %
  10. % b) all additions are clearly marked, in amongst all this header information,
  11. %    *and* where the addition has been made,
  12. %
  13. % c) if you make any additions, then change the name of the file, and
  14. %
  15. % d) you don't try to make any money out of this.
  16. %
  17. % See the Gnu manifesto for details on why software ought to be free.
  18. %
  19. % If you are worrying about the first three clauses, they're just
  20. % there to make sure tons of different styles with the same name 
  21. % don't proliferate.  If you want to remove a definition, then just
  22. % comment it out (adding a %, not deleting anything).
  23. %
  24. % Tugboat are given permission to publish any or all of this.
  25. %
  26. % This style provides a pile of lambda-calculus and list-handling
  27. % macros of an incredibly obtuse nature.  Read Lambda.tex to find out
  28. % what they all do and how they do it.  This \TeX\ code was formally
  29. % verified.
  30. %
  31. % Alan Jeffrey, 25 Jan 1990.
  32.  
  33. \def\Identity#1{#1}
  34.  
  35. \def\Error%
  36.    {\errmessage{Abandon verification all 
  37.                 ye who enter here}}
  38.  
  39. \def\First#1#2{#1}
  40. \def\Second#1#2{#2}
  41.  
  42. \def\Compose#1#2#3{#1{#2{#3}}}
  43.  
  44. \def\Twiddle#1#2#3{#1{#3}{#2}}
  45.  
  46. \let\True=\First
  47. \let\False=\Second
  48. \let\Not=\Twiddle
  49.  
  50. \def\And#1#2{#1{#2}\False}
  51. \def\Or#1#2{#1\True{#2}}
  52.  
  53. \def\Lift#1#2#3#4{#1{#4}{#2}{#3}{#4}}
  54.  
  55. \def\Lessthan#1#2{\TeXif{\ifnum#1<#2 }}
  56.  
  57. \def\gobblefalse\else\gobbletrue\fi#1#2%
  58.    {\fi#1}
  59. \def\gobbletrue\fi#1#2%
  60.    {\fi#2}
  61. \def\TeXif#1%
  62.    {#1\gobblefalse\else\gobbletrue\fi}
  63.  
  64. \def\Nil#1#2{#2}
  65. \def\Cons#1#2#3#4{#3{#1}{#2}}
  66. \def\Stream#1{\Cons{#1}{\Stream{#1}}}
  67. \def\Singleton#1{\Cons{#1}\Nil}
  68.  
  69. \def\Head#1{#1\First\Error}
  70. \def\Tail#1{#1\Second\Error}
  71.  
  72. \def\Foldl#1#2#3%
  73.    {#3{\Foldl@{#1}{#2}}{#2}}
  74. \def\Foldl@#1#2#3#4%
  75.    {\Foldl{#1}{#1{#2}{#3}}{#4}}
  76. \def\Foldr#1#2#3%
  77.    {#3{\Foldr@{#1}{#2}}{#2}}
  78. \def\Foldr@#1#2#3#4%
  79.    {#1{#3}{\Foldr{#1}{#2}{#4}}}
  80.  
  81. \def\Cat#1#2{\Foldr\Cons{#2}{#1}}
  82.  
  83. \def\Reverse{\Foldl{\Twiddle\Cons}\Nil}
  84.  
  85. \def\All#1{\Foldr{\Compose\And{#1}}\True}
  86. \def\Some#1{\Foldr{\Compose\Or{#1}}\False}
  87. \def\Isempty{\All{\First\False}}
  88.  
  89. \def\Filter#1%
  90.    {\Foldr{\Lift{#1}\Cons\Second}\Nil}
  91.  
  92. \def\Map#1{\Foldr{\Compose\Cons{#1}}\Nil}
  93.  
  94. \def\Insert#1#2#3%
  95.    {#3{\Insert@{#1}{#2}}{\Singleton{#2}}}
  96. \def\Insert@#1#2#3#4%
  97.    {#1{#2}{#3}%
  98.       {\Cons{#2}{\Cons{#3}{#4}}}%
  99.       {\Cons{#3}{\Insert{#1}{#2}{#4}}}}
  100. \def\Insertsort#1{\Foldr{\Insert{#1}}\Nil}
  101.  
  102. \def\Unlistize#1{[#1\Unlistize@{}]}
  103. \def\Unlistize@#1{#1\Foldr\Commaize{}}
  104. \def\Commaize#1#2{, #1#2}
  105.  
  106. \def\Listize[#1]%
  107.    {\Listize@#1,\relax]}
  108. \def\Listize@#1,#2]%
  109.    {\TeXif{\ifx\relax#2}%
  110.         {\Singleton{#1}}%
  111.         {\Cons{#1}{\Listize@#2]}}}
  112.  
  113. \def\Show#1[#2]%
  114.    {\Unlistize{#1{\Listize[#2]}}}
  115.  
  116.  
  117.